const axios = require('axios');
const baseURL = 'https://api.openai.com';
const url = '/v1/engines/davinci-codex/completions';

const prompt = '你好\n';
const apiKey = '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';

const data = {
    prompt: prompt,
    max_tokens: 100,
    temperature: 0.5,
    n: 1,
    stop: '\n'
}

const headers = {
    'Content-Type': 'application/json',
    'Authorization': `Bearer ${apiKey}`
}

axios({
    method: 'post',
    baseURL,
    url,
    headers,
    data
}).then(response => {
    console.log("response");
    const {data} = response;
    console.log(JSON.stringify(data));
}).catch(error => {
    console.log("error");
    const {response} = error;
    const {data} = response;
    console.log(JSON.stringify(data));
});
